package cn.han.jdbc;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

public class Test3 {
    public static void main(String[] args) throws Exception {
        /*1.注册驱动
         * 2.获取数据库的连接
         * 3.获取传输器
         * 4.执行SQL
         * 5.解析结果集
         * 6.释放资源*/
        Class.forName("com.mysql.jdbc.Driver");
        String url = "jdbc:mysql://localhost:3306/cgb2018";
        Connection c = DriverManager.getConnection(url,"root","root");
        Statement s = c.createStatement();
        ResultSet r = s.executeQuery("select * from dept;");
        while (r.next()){
            int a = r.getInt(1);
            System.out.println(a);
        }
        r.close();
        s.close();
        c.close();
    }
}
